package com.zh.note.leetcode.string;

/**
 * 14. 最长公共前缀
 * 输入：strs = ["flower","flow","flight"]
 * 输出："fl"
 */
public class LongestCommonPrefix {

    public String longestCommonPrefix(String[] strs) {

        String res = strs[0];
        for (int i = 1; i < strs.length; i++) {
            while (!strs[i].startsWith(res)) {
                if (res.length() == 0) {
                    return "";
                }
                res = res.substring(0, res.length() - 1);
            }
        }
        return res;

    }
}
